<% layout('/layouts/default.html', {title: '扣车原因管理', libs: ['dataGrid']}){ %>
<div class="main-content">
	<div class="box box-main">
		<div class="box-header">
			<div class="box-title">
				<i class="fa icon-notebook"></i> ${text('主要故障')}
			</div>
			<div class="box-tools pull-right">
				<a href="#" class="btn btn-default" id="btnSearch" title="${text('查询')}"><i class="fa fa-filter"></i> ${text('查询')}</a>
			</div>
		</div>
		<div class="box-body">
			<#form:form id="searchForm" model="${tblZdKcyy}" action="${ctx}/tbl/kclb/tblZdKcyy/listDataSelect" method="post" class="form-inline">
				<div class="form-group">
					<label class="control-label">${text('故障类别')}：</label>
					<div class="control-inline width-120">
						<#form:select path="kclbCode" items="${kclbList}" itemLabel="kclbName" itemValue="kclbCode" class="form-control"/>
					</div>
				</div>
				<div class="form-group">
					<button type="submit" class="btn btn-primary btn-sm">${text('查询')}</button>
					<button onclick="confirmBtn()" class="btn btn-default btn-sm">${text('确认')}</button>
				</div>
			</#form:form>
			<table id="dataGrid"></table>
			<!-- <div id="dataGridPage"></div> -->
		</div>
	</div>
</div>
<% } %>
<script>
var faultCodeStr=[];
var faultReasonStr=[];
// 初始化DataGrid对象
$('#dataGrid').dataGrid({
	searchForm: $("#searchForm"),
	multiselect:true,
	rownumWidth:40,
	shrinkToFit:false,
	columnModel: [
		{header:'${text("故障原因编码")}', name:'faultCode', index:'a.fault_code', width:150, align:"left", frozen:true},
		{header:'${text("故障原因")}', name:'faultName', index:'a.fault_name', width:150, align:"left"}
	],
	// 加载成功后执行事件
	ajaxSuccess: function(data){
	},
	
	//选择行后调用（id:行id，isSelect：是否是选中，event：事件）
	onSelectRow: function(id, isSelect, event) {
		var rowData = $('#dataGrid').dataGrid('getRowData',id);
		if(isSelect){
			faultCodeStr.push(rowData.faultCode);
			faultReasonStr.push(rowData.faultName);
			//去重
			faultCodeStr = faultCodeStr.filter((item, index) => {

				return faultCodeStr.indexOf(item) === index;

			});
			
			faultReasonStr = faultReasonStr.filter((item, index) => {

				return faultReasonStr.indexOf(item) === index;

			});
		}else{
			//取消则删除元素
			faultCodeStr = faultCodeStr.filter(item => item != rowData.faultCode);
			faultReasonStr = faultReasonStr.filter(item => item != rowData.faultName);
		}
		console.log(faultCodeStr); 
		console.log(faultReasonStr); 
	},
	
	// 单击列表表头上的全选按钮时调用（ids：选中的id数组，isSelect：是否选中）
	onSelectAll: function(ids, isSelect){
		if(isSelect){
			faultCodeStr = [];
			faultReasonStr = [];
			ids.forEach(item=>{
				var rowData = $('#dataGrid').dataGrid('getRowData',item);
				faultCodeStr.push(rowData.faultCode);
				faultReasonStr.push(rowData.faultName);
			})
		}else{
			//取消则删除元素
			faultCodeStr = [];
			faultReasonStr = [];
		}
		console.log(faultCodeStr); 
		console.log(faultReasonStr); 
	},
	
	// 双击表格行时调用（id：双击的行号，rownum：双击的行位置，column：双击的列）
	ondblClickRow: function(id, rownum, colnum, event){
		console.log(3);
	},
}).dataGrid('setLabel', 'rn', '序号');

function confirmBtn(){
	var index = parent.layer.getFrameIndex(window.name);
	parent.returnValueC=faultCodeStr;
	parent.returnValueR=faultReasonStr;
	parent.layer.close(index);
}
</script>